<?php

namespace Home\Controller;

/**
 * Description of OutInterfaceController.class控制器实例
 * 
 * @author songanwei
 * @date 2016-1-5
 */
class OutInterfaceController extends ParentController {

    /**
     * @description 返回所有省份数据
     * @modify songanwei 2016-01-04
     */
    public function provice() {
        $provinceModel = D('Province');
        $provinces = $provinceModel->getAll();
        returnJson(200, 200, $provinces);
    }

    /**
     * @description 返回所在省的城市数据
     * @modify songanwei 2016-01-04
     */
    public function city() {
        $provinceId = I('post.province');
        $cityModel = D('City');
        $citys = $cityModel->getAllByProvince($provinceId);
        foreach ($citys as $key => &$citysItem) {
           $citysItem['name'] = explode('/', $citysItem['name'])[0];
        }
        unset($citysItem);
        returnJson(200, 200, $citys);
    }

    /**
     * @description 返回城市的所有区域
     * @modify songanwei 2016-01-04
     */
    public function area() {
        $cityId = I('post.city');
        $districtModel = D('District');
        $areas = $districtModel->getAllByCity($cityId);
        foreach ($areas as $key => &$areasItem) {
           $areasItem['name'] = explode('/', $areasItem['name'])[0];
        }
        unset($areasItem);
        returnJson(200, 200, $areas);
    }

}
